// 无访问限制路由
export const defaultRouter = [
  '/',
  '/notFound/page404',
  '/login',
  '/resetPassword',
  '/enterprise',
  '/withoutPermission'
]
const checkChidrenPageRouter = (children: Record<string, any>) => {
  let f = false
  children.forEach((item: Record<string, any>) => {
    if (item?.pageRouter === 0) {
      f = true
    }
  })
  return f
}

export const deep = (arr: any) => {
  const res = [] as any
  function inn(arr: any) {
    arr.length && arr.forEach((item: any) => {
      if (item?.children.length === 0) {
        res.push(item?.router)
      }
      if (item.children && item.children.length && checkChidrenPageRouter(item.children)) {
        res.push(item?.router)
      }
      item.children && inn(item.children)
    })
  }
  inn(arr)
  return [...new Set(res)]
}

/**
 * 获取最终路由字典生成Map结构
 * @param permissionsRouters
 * @returns
 */
export const getResRouter = (permissionsRouters: Record<string, any>) => {
  const keyMap = {} as Record<string, any>
  permissionsRouters.forEach((item:string) => {
    if (!keyMap[item]) {
      keyMap[item] = true
    }
  })
  return keyMap
}
